package cloud.shyidong.tenant.service.impl;

import cloud.shyidong.core.request.LongIdRequest;
import cloud.shyidong.core.service.AbstractTenantService;
import cloud.shyidong.core.util.ObjectUtils;
import cloud.shyidong.tenant.dao.TenantPayDao;
import cloud.shyidong.tenant.entity.TenantPayEntity;
import cloud.shyidong.tenant.request.TenantPayInsertRequest;
import cloud.shyidong.tenant.request.TenantPayPageRequest;
import cloud.shyidong.tenant.request.TenantPaySaveRequest;
import cloud.shyidong.tenant.request.TenantPayUpdateRequest;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 租户支付业务处理
 * </p>
 *
 * @author syd
 * @since 2023-09-18 15:34:26
 */
@Service
public class PayService extends AbstractTenantService<TenantPayDao, TenantPayEntity, LongIdRequest, TenantPayInsertRequest, TenantPayUpdateRequest, TenantPayPageRequest> {
    
    public TenantPayEntity getByTenantId(Long id) {
        QueryWrapper<TenantPayEntity> tenantPayEntityQueryWrapper = new QueryWrapper<>();
        tenantPayEntityQueryWrapper.eq("tenant_id", id);
        return getDao().selectOne(tenantPayEntityQueryWrapper);
    }
    
    public TenantPayEntity save(TenantPaySaveRequest tenantPaySaveRequest) {
        TenantPayEntity tenantPayEntity = getByTenantId(tenantPaySaveRequest.getTenantId());
        if (ObjectUtils.isNull(tenantPayEntity)) {
            TenantPayInsertRequest tenantPayInsertRequest = mapper.map(tenantPaySaveRequest, TenantPayInsertRequest.class);
            return this.insert(tenantPayInsertRequest);
        }
        TenantPayUpdateRequest tenantPayUpdateRequest = mapper.map(tenantPaySaveRequest, TenantPayUpdateRequest.class);
        return this.update(tenantPayUpdateRequest);
    }
    
}
